package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.OtherStudentDao;
import com.itheima.edu.info.manager.dao.StudentDao;
import com.itheima.edu.info.manager.domain.Student;

public class StudentService {
   private OtherStudentDao studentDao = new OtherStudentDao();

   public boolean addStudent(Student stu){
       //创建StudentDao(库管）
       return StudentDao.addStudent(stu);
   }
   public static boolean isExists(String id){
       Student[] stus = StudentDao.findAllStudent();
       //假设id在数组中不存在
       boolean exists =false;
       //遍历数组，获取每一个学生对象，准备进行判断
       for (int i = 0; i <stus.length; i++) {
           Student student = stus[i];
           if (student != null && student.getId().equals(id)){
            exists=true;
            break;
           }
       }
       return  exists;
   }


    //查看学生方法
    public Student[] findAllStudent() {
       Student[] allStudent = StudentDao.findAllStudent();
       boolean flag =false;
        for (int i = 0; i <allStudent.length ; i++) {
            Student stu = allStudent[i];
            if (stu != null){
                flag=true;
                break;
            }
        }
        if (flag){
            return  allStudent;
        }else {
            return null;
        }
    }
    public void updateStudent(String updateId, Student newStu) {
        StudentDao.updateStudent(updateId,newStu);
    }

    public void deleteStudentById(String delId) {
        StudentDao.deleteStudentById(delId);
    }

}
